import os
import base64
from openai import OpenAI
from API_KEY import *

def image_to_base64(image_path):    #转成base64
    with open(image_path, "rb") as image_file:
        return base64.b64encode(image_file.read()).decode('utf-8')

client = OpenAI(
    base_url="https://ark.cn-beijing.volces.com/api/v3",
    api_key=YI_KEY,
)

image_path = "image.png"
base64_image = image_to_base64(image_path)

response = client.chat.completions.create(
    model="doubao-seed-1-6-flash-250828",
    messages=[
        {
            "role": "user",
            "content": [
                {
                    "type": "image_url",
                    "image_url": {
                         "url": f"data:image/jpeg;base64,{base64_image}"
                    },
                },
                {"type": "text", "text": "这是什么地方？"},
            ],
        }
    ],
)

print(response.choices[0].message.content)